package com.etc.service;

import javax.annotation.Resource;

import com.etc.dao.SysUserMapper;
import com.etc.entity.SysUser;
import com.etc.entity.SysUserExample;
import com.etc.entity.SysUserKey;
import com.etc.utils.Stringutils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author Administrator
 * 员工业务层
 *
 */
@Service
public class SysStaftService {

	private static  final Logger log = LoggerFactory.getLogger(SysStaftService.class);
	

	@Resource
	private SysUserMapper sysUserMapper;
	
	/**
	 * 添加员工
	 * @param staft
	 * @return
	 */

	public Integer add(SysUser staft){
		Integer restlet =null;
		try{
			staft.setSaveDate("");
			staft.setRole("3");
			restlet = sysUserMapper.insert(staft);
		}catch (Exception e) {
			log.error(e.getLocalizedMessage());
		}

		return restlet;
	}
//
//	/**
//	 * 添加员工
//	 * @param id
//	 * @return
//	 */
//	public SysStaff add(String id){
//		SysStaff restlet =null;
//		try{
//			SysStaffKey staffKey = new SysStaffKey();
//			staffKey.setId(Integer.valueOf(id));
//			restlet = sysUserMapper.selectByPrimaryKey(staffKey);
//		}catch (Exception e) {
//			log.error(e.getLocalizedMessage());
//		}
//
//		return restlet;
//	}
	
	/**
	 * 查询所有员工
	 * @return
	 */
	public PageInfo findSysStaff(int page1){
		    PageHelper.startPage(page1, 10);

			List<SysUser> sysUsers = new ArrayList<SysUser>();

			SysUserExample sysUserExample = new SysUserExample();
			SysUserExample.Criteria criteria = sysUserExample.createCriteria();
			criteria.andRoleEqualTo("3");
			sysUsers = sysUserMapper.selectByExample(sysUserExample);

		    PageInfo pageInfo = new PageInfo(sysUsers);
			return pageInfo;
	}
	
	
	/**
	 * 删除用户
	 * @param id
	 * @return
	 */
	public Integer delete(String id){
		Integer restlet = null;
		if(!Stringutils.isEmpty(id)){
			SysUserKey staffKey = new SysUserKey();
			staffKey.setId(Integer.valueOf(id));
			try{
				restlet = sysUserMapper.deleteByPrimaryKey(staffKey);
			}catch (Exception e) {
				log.error(e.getLocalizedMessage());
			}
		}
		return restlet;
	}

}
